﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using CNTVNow.Web.Helpers.Common;

namespace CNTVNow.Web.Models
{
    public class HomeModel
    {
        public List<New> GetNewsTopBanner()
        {
            return (from n in SingletonContext.CntvContext.News 
                    where (n.NewsHomePagePositionID == Config.PositionTopBanner()) 
                    orderby n.LastModifiedDate descending 
                    select n).Take(Config.NewsTopNumber()).ToList();
        }
        public List<New> GetNewsUnderTopBanner()
        {
            return (from n in SingletonContext.CntvContext.News 
                    where (n.NewsHomePagePositionID == Config.PositionUnderTopBanner()) 
                    orderby n.LastModifiedDate descending 
                    select n).Take(Config.NewsUnderTopNumber()).ToList();
        }
        public List<New> GetNewsLatest()
        {
            return (from n in SingletonContext.CntvContext.News 
                    where (n.NewsHomePagePositionID == Config.PositionLatestNews()) 
                    orderby n.LastModifiedDate descending 
                    select n).Take(Config.NewsLatestNumber()).ToList();
        }
        public List<New> GetNewsLeft()
        {
            return (from n in SingletonContext.CntvContext.News 
                    where (n.NewsHomePagePositionID == Config.PositionLeftNews()) 
                    orderby n.LastModifiedDate descending 
                    select n).Take(Config.NewsLeftNumber()).ToList();
        }
        public List<New> GetNewsMiddle()
        {
            //var newsNews = (from n in SingletonContext.CntvContext.News
            //                where (n.NewsCatParentID == FixCommon.NewsId) && (n.NewsHomePagePositionID == Config.PositionMiddleNews())
            //                  orderby n.LastModifiedDate descending
            //                  select n).Take(FixCommon.NewsNumberMiddleHome).ToList();
            var newsNews = (from n in SingletonContext.CntvContext.News
                            where (n.NewsCategoryID == FixCommon.NewsId) && (n.NewsHomePagePositionID == Config.PositionMiddleNews())
                            orderby n.LastModifiedDate descending
                            select n).Take(FixCommon.NewsNumberMiddleHome).ToList();
            var newsSport = (from n in SingletonContext.CntvContext.News
                             where (n.NewsCategoryID == FixCommon.SportId) && (n.NewsHomePagePositionID == Config.PositionMiddleNews())
                            orderby n.LastModifiedDate descending
                            select n).Take(FixCommon.NewsNumberMiddleHome).ToList();
            var newsMusic = (from n in SingletonContext.CntvContext.News
                             where (n.NewsCategoryID == FixCommon.MusicId) && (n.NewsHomePagePositionID == Config.PositionMiddleNews())
                            orderby n.LastModifiedDate descending
                            select n).Take(FixCommon.NewsNumberMiddleHome).ToList();
            var newsMovie = (from n in SingletonContext.CntvContext.News
                             where (n.NewsCategoryID == FixCommon.MovieId) && (n.NewsHomePagePositionID == Config.PositionMiddleNews())
                            orderby n.LastModifiedDate descending
                            select n).Take(FixCommon.NewsNumberMiddleHome).ToList();
            var newsLifeStyle = (from n in SingletonContext.CntvContext.News
                                 where (n.NewsCategoryID == FixCommon.LifeStyleId) && (n.NewsHomePagePositionID == Config.PositionMiddleNews())
                            orderby n.LastModifiedDate descending
                            select n).Take(FixCommon.NewsNumberMiddleHome).ToList();
            var newsCntv = (from n in SingletonContext.CntvContext.News
                            where (n.NewsCategoryID == FixCommon.CntvliveId) && (n.NewsHomePagePositionID == Config.PositionMiddleNews())
                            orderby n.LastModifiedDate descending
                            select n).Take(FixCommon.NewsNumberMiddleHome).ToList();
            return  newsNews.Union(newsSport).Union(newsMusic).Union(newsMovie).Union(newsLifeStyle).Union(newsCntv).ToList();
            
        }
    }
}